﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SlamCms.SharePoint.Publishing.WebParts;
using SlamCms.SharePoint.Core;
using SlamCms.Data.Repositories;
using System.Linq;

namespace SlamCms.SharePoint.Publishing.Pages
{
    public partial class DeleteComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                this.btnAccept.Click += new EventHandler(btnAccept_Click);
                this.btnCancel.Click += new EventHandler(btnCancel_Click);

               
            }

           

        }


        protected void btnAccept_Click(object sender, EventArgs e)
        {
            int id = Request.QueryString["commentId"] != null ? int.Parse(Request.QueryString["commentId"].ToString()) : -1;

            if (id > -1)
            {
                 Delete(id);
                //if (rowsAffected == 1)
                //{
                    this.Page.Response.Clear();
                    this.Page.Response.Write("<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, 1);</script>");
                    this.Page.Response.End();
                //}
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.Page.Response.Clear();
            //string returnValue = txtFromDate.Text + ";" + txtToDate.Text + ";" + ContentSource.Items[ContentSource.SelectedIndex].Value;
            this.Page.Response.Write("<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(0,1);</script>");
            this.Page.Response.End();
        }

        private void Delete(int commentId)
        {
            var comment = SlamCmsContext.Entities.Comments.Where(c => c.CommentID.Equals(commentId)).FirstOrDefault();
            comment.CommentStatusID = "s2";

            SlamCmsContext.Entities.SaveChanges();
            //CommentRepository repository = new CommentRepository(SlamCmsContext.Data.Settings.DatabaseConnectionFactory.Invoke());
            //return repository.UpdateCommentStatus(commentId);
            
        
        }

      
    }
}
